<div class="title"> <span>设置主页封面</span> </div>
  <div id="coverpic_box">
    <img id="coverpic" src="<!--{$user.coverpic.pc}-->?<!--{$iCMS.TIME}-->" alt="个人封面" onerror="iCMS.user.nocover(this);">
  </div>
  <span class="label label-important">封面图片建议尺寸：960像素 * 300像素</span>
  <div class="clearfix mt10"></div>
  <form id="coverpic_upload" action="<!--{iCMS:router url='/user'}-->" method="post" enctype="multipart/form-data" target="iCMS_FRAME">
    <input name="action" type="hidden" value="profile" />
    <input name="pg" type="hidden" value="custom" />
    <input type="file" name="upfile" class="hide">
    <a id="upload" href="javascript:;" class="btn btn-primary"><i class="fa fa-upload"></i> 更换封面</a> <a class="btn" href="javascript:meituxx();"><i class="fa fa-edit"></i> 使用美图秀秀编辑封面</a>
  </form>
  <div class="coverpic_editor hide mt10">
    <script src="<!--{$iCMS.UI}-->/meitu/xiuxiu.js" type="text/javascript"></script>
    <div id="coverpic_editor"></div>
  </div>
  <script>
$(function() {
    $("#upload").click(function() {
        $("input[name=upfile]").click();
    })
    $("input[name=upfile]").change(function() {
        $("#coverpic_upload").submit();
    })
})
function callback(obj) {
	$("#coverpic").attr({
		src: obj.url+ Math.random()
	}).show();
}
function meituxx(){
  $('.coverpic_editor').show();
  $('#coverpic_editor').html('');
  xiuxiu.setLaunchVars("customMenu", ["decorate","puzzle"]);
  xiuxiu.setLaunchVars("cropPresets", "960x300");
  xiuxiu.setLaunchVars("file_name", "<!--{$me.uid}-->");
  xiuxiu.embedSWF("coverpic_editor",3,"100%","500");
  xiuxiu.setUploadURL("<!--{iCMS:router url='/user'}-->");

  xiuxiu.onInit = function (){
  	var coverpic= $('#coverpic').attr('src');
    xiuxiu.loadPhoto(coverpic);
    xiuxiu.setUploadArgs({'action':'profile','pg':'custom','format':'json'});
    xiuxiu.setUploadDataFieldName ('upfile');
    xiuxiu.setUploadType(2);
  }
  xiuxiu.onBeforeUpload = function (data, id){
    var size = data.size;
    if(size > 2 * 1024 * 1024){
      alert("图片不能超过2M");
      return false;
    }
    if(data.width!=960||data.height!=300){
    	alert("封面图片建议尺寸：960像素 * 300像素,或者裁剪成16:5等比例图片");
    	return false;
    }
    return true;
  }
  xiuxiu.onUploadResponse = function (data){
    var a = $.parseJSON(data);
    iCMS.alert(a.msg,a.code);
    if(a.code){
      window.setTimeout(function(){
        window.location.reload();
      },2000);
    }
  }
}
</script>

